<?php
$bartUserServices = new BartuserService();
$paymentServices = new PaymentServices();
$invoiceServices = new InvoiceService();
$tool = new Tool();
$orderServices = new OrdersService();
$currencyService = new CurrencyServices();
if(isset($_GET['opt']))
{
	$opt = $_GET['opt'];
	$moduleID = $moduleService->getModuleIDByFuncAndOpt($context, $result, $func, $opt);
	$permit = $permitService->checkPermition($context, $result, $_SESSION['user']['type'], $moduleID);

	if($opt == "paymentList" && $permit ==true)
	{
			
		$start=$p->findStart($configPage['limit']);
		$count=$orderServices->countByStatus($context, $result, "3,4");
		$pages=$p->findPages($count,$configPage['limit']);
		$page_list = $p->pagesList($_GET['page'],$pages,$configPage);
		$orderList = $orderServices->getAllOrderDisplayByTypeByRange($context, $result, "3,4", $start, $configPage['limit']);
		$total = "Page ".$_GET['page']." in ".$pages. " Pages";
		$smarty->assign('tool', $tool);	
		$smarty->assign('total', $total);
		$smarty->assign('page_list', $page_list);
		$smarty->assign('orderList', $orderList);
		$smarty->display($templateDir . "/temp1/listPayment.tpl");
			
	}

	if($opt == 'viewPayment' && $permit ==true)
	{
		if(isset($_GET['id'])&& is_numeric($_GET['id']))
		{
			$paymentList = $paymentServices->getPaymentByOrderID($context, $result, $_GET['id']);
			//echo "<pre>";
			//print_r($paymentList);
			if($paymentList[0]->getOrder()->getOrdersDomain()->getType()==3)
			{
				$smarty->assign('tool', $tool);	
				$smarty->assign('paymentList', $paymentList);		
				$smarty->display($templateDir . "/temp1/viewPayment.tpl");
			}
			else {
				$smarty->assign('tool', $tool);	
				$smarty->assign('paymentList', $paymentList);
				$smarty->display($templateDir . "/temp1/viewLastPayment.tpl");
			}
		}
	}
		
	if($opt == "searchPay" && $permit ==true)
	{
		if(isset($_POST['dateFrom']) && isset($_POST['dateTo']) && $_POST['dateFrom'] != '' && $_POST['dateTo'] != '')
		{
			$dateFrom = $_POST['dateFrom'];
			$dateTo = $_POST['dateTo'];
		}
		else {
			$dateFrom = '0000-00-00';
			$dateTo = date('Y-m-d', time());
		}
		$start=$p->findStart($configPage['limit']);
		$count = $orderServices->countAllByStatusByOrderDate($context, $result, "3,4", $dateFrom, $dateTo);
		$pages=$p->findPages($count,$configPage['limit']);
		$page_list = $p->pagesList($_GET['page'],$pages,$configPage);
		$orderList = $orderServices->findAllByStatusByOrderDateByRange($context, $result, "3,4", $start, $configPage['limit'], $dateFrom, $dateTo);
		$total = "Page ".$_GET['page']." in ".$pages. " Pages";
		$smarty->assign('tool', $tool);	
		$smarty->assign('total', $total);
		$smarty->assign('page_list', $page_list);
		$smarty->assign('orderList', $orderList);
		$smarty->display($templateDir . "/temp1/listPayment.tpl");
		
	}
	if($opt == "exchangeRate" && $permit ==true)
	{
		$date = date('Y-m-d');
		$currencyList = $currencyService->findAllCurrency($context, $result);
		$smarty->assign('currencyList',$currencyList);
		$smarty->assign('date',$date);
		$smarty->display($templateDir . "/temp1/exchangeRate.tpl");
		
	}
		
}
?>